<?
  require_once("../inc/functions.php");
  require_once("../class/DBConnection.php");
  
  if($_SERVER['SERVER_NAME'] == "localhost") {
  	DBConnection::connect("../config/connection_local.cfg");
  } else if($_SERVER['SERVER_NAME'] == "sokolzdelov.dadena.com") {
    DBConnection::connect("../config/connection_production.cfg");
  }
  
  $id_utkani = $_GET['id_utkani'];
  $result = "success=1";
  $i = 1;
  
  $query = mysql_query("SELECT (SELECT CONCAT(h.PRIJMENI,' ', SUBSTR(h.JMENO, 1, 1), '.') FROM hrac h WHERE h.ID_HRAC=s.ID_HRAC) as jmeno,
            s.BRANKY as goly, s.ZK as zk, s.CK as ck
            FROM soupiska s JOIN utkani u 
            ON (s.ID_UTKANI=u.ID_UTKANI) WHERE s.STRIDAL='-1' and u.ID_UTKANI='$id_utkani' 
            ORDER BY s.ID_SOUPISKA ASC");
        
  while($fetch = MySQL_Fetch_Array($query)){
      $name = $fetch["jmeno"];
      $g = $fetch["goly"];
      $zk = $fetch["zk"];
      $ck = $fetch["ck"];
      if($zk == 1 && $ck == 1) $zk = 0;
      $result.="&p".$i."=".$name."&g".$i."=".$g."&zk".$i."=".$zk."&ck".$i."=".$ck;
      $i++;
  }
  
  $query = mysql_query("SELECT (SELECT CONCAT(h.PRIJMENI,' ', SUBSTR(h.JMENO, 1, 1), '.') FROM hrac h WHERE h.ID_HRAC=s.ID_HRAC) as jmeno,
            (SELECT CONCAT(h.PRIJMENI,' ', SUBSTR(h.JMENO, 1, 1), '.') FROM hrac h WHERE h.ID_HRAC=s.STRIDAL) as jmeno_str,
            s.BRANKY as goly, s.ZK as zk, s.CK as ck
            FROM soupiska s JOIN utkani u 
            ON (s.ID_UTKANI=u.ID_UTKANI) WHERE s.STRIDAL!='-1' and u.ID_UTKANI='$id_utkani' 
            ORDER BY s.ID_SOUPISKA ASC");
        
  while($fetch = MySQL_Fetch_Array($query)){
      $name = $fetch["jmeno"];
      $name_sub = $fetch["jmeno_str"];
      $g = $fetch["goly"];
      $zk = $fetch["zk"];
      $ck = $fetch["ck"];
      if($zk == 1 && $ck == 1) $zk = 0;
      $result.="&p".$i."=".$name."&s".$i."=".$name_sub."&g".$i."=".$g."&zk".$i."=".$zk."&ck".$i."=".$ck;
      $i++;
  }
  
  echo $result;
  DBConnection::disconnect();
?>